package cn.kent.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class RabbitConfig {
    public static final String DELAY_MSG_QUEUE_NAME = "delay_msg_queue_name";
    public static final String DELAY_MSG_EXCHANGE_NAME = "delay_msg_exchange_name";

    @Bean
    Queue delayQueue(){
        return new Queue(DELAY_MSG_QUEUE_NAME, true, false,false);
    }
    @Bean
    CustomExchange customExchange(){
        HashMap<String, Object> args = new HashMap<>();
        // 指定交换机类型
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAY_MSG_EXCHANGE_NAME, "x-delayed-message",true, false, args);
    }
    @Bean
    Binding delayBinding(){
        return BindingBuilder.bind(delayQueue())
                .to(customExchange())
                .with(DELAY_MSG_QUEUE_NAME)
                .noargs();
    }
}
